<template>
	<!-- 过程检验 -->
	<div>
		<v-container row class="text-subtitle-1 d-flex justify-center  align-left">

			<v-btn class="ml-2 mt-7" small tile color="primary" @click="openProcessCheckDialog">
				添加过程检验
			</v-btn>

			<v-divider class="mx-4" inset vertical></v-divider>
			<v-row class="mt-2">
				<v-col cols="12" sm="3" md="2">
					<v-text-field label="项目号" v-model="processQuery.projectCode" dense outlined>
					</v-text-field>
				</v-col>
				<!-- sm="6" md="2" -->
				<v-col cols="12" sm="3" md="2">
					<v-text-field label="项目名称" v-model="processQuery.projectName" dense outlined>
					</v-text-field>
				</v-col>
				<v-col cols="12" sm="3" md="2">
					<v-text-field label="设备名称" v-model="processQuery.equipmentName" dense outlined>
					</v-text-field>
				</v-col>
				<v-col cols="12" sm="2" md="2">
					<v-text-field label="工单号" v-model="processQuery.childrenCode" dense outlined>
					</v-text-field>
				</v-col>
				<v-col cols="12" sm="2" md="2">
					<v-checkbox v-model="processQuery.checkResult" dense label="是否异常"></v-checkbox>
				</v-col>
				<!-- ml-n16 前面加n是间距 -->
				<!-- class="ml-n16 mx-auto" -->
				<v-col cols="12" sm="2" md="2">
					<v-btn depressed color="primary" @click="processQueryLoad">查询</v-btn>
					<v-btn class="ml-3" depressed color="primary" @click="refreshprocessQueryLoad">
						刷新</v-btn>
				</v-col>
			</v-row>
		</v-container>
		<br />
		<!-- :single-select="true" -->
		<v-data-table :headers="processHeaderList" :items="processDataList" small fixed-header item-key="id" dense
			class="text-no-wrap" loading-text="正在加载请稍等......" :options.sync="processOptions" show-select
			:footer-props="vuetifyDefaultPage" :loading="processLoading" :server-items-length="processTotalCount">
			<template v-slot:item.checkresult="{ item }">
				<a :style="item.checkresult?'color:red;':'color:green;'">{{item.checkresult?"是":"否"}}</a>
			</template>
		</v-data-table>


		<v-dialog v-model="processCheckDialog" width="1000px">
			<v-card>
				<v-card-title>添加过程检验</v-card-title>
				<v-card-text>
					<v-row>
						<v-col cols="12">
							<v-combobox v-model="processModel.childrenid" :items="childrenItems" label="选择工单"
								persistent-hint small-chips dense outlined @input="selectChildrenEvent">
							</v-combobox>
						</v-col>
						<v-col cols="12">
							<userselectcomment :selectUserCommentModel="userCommentModel" :callBack="setUserCallBack">
							</userselectcomment>
						</v-col>
						<v-col cols="12">
							<v-textarea outlined name="input-7-4" label="检验结果" v-model="processModel.description"
								:value="processModel.description" dense>
							</v-textarea>
						</v-col>
						<v-col cols="12">
							<v-textarea outlined name="input-7-4" label="改进方法" v-model="processModel.improvedmethod"
								:value="processModel.improvedmethod" dense>
							</v-textarea>
						</v-col>
						<v-col cols="12">
							<v-checkbox v-model="processModel.checkresult" label="是否异常" dense></v-checkbox>
						</v-col>
					</v-row>
				</v-card-text>
				<v-card-actions>
					<v-spacer></v-spacer>
					<v-btn class="ml-3" color="success" :disabled="processModel.childrenid==null" text
						@click="processSubmit">
						确定
					</v-btn>
					<v-btn color="blue darken-1" text @click="cannel">
						退出
					</v-btn>
				</v-card-actions>
			</v-card>

		</v-dialog>
	</div>
</template>
<script>
	import UserSelectComment from '../../spm/components/UserSelect.vue'
	export default {
		name: 'mes_process_check',
		components: {
			userselectcomment:UserSelectComment
		},
		data() {
			return {
				userCommentModel: {
					loadSelectUserItemsUrl: ``,
					isReturnObj: true,
					label: '选择加工人员(必填)',
					paramterUserList: null
				},
				processModel: {},
				processCheckDialog: false,
				processQuery: {
					'equipmentName': '',
					'projectCode': '',
					'projectName': '',
					'childrenCode': '',
					'checkResult': null
				},
				processHeaderList: [{
						text: '项目号',
						value: 'childrenorder.projectcode',
						filterable: true
					},
					{
						text: '项目名称',
						value: 'childrenorder.projectname',
						filterable: true
					},
					{
						text: '设备名称',
						value: 'childrenorder.name',
						filterable: true
					},
					{
						text: '工单号',
						value: 'childrenorder.code',
						filterable: true
					},
					{
						text: '图号',
						value: 'childrenorder.piccode',
						filterable: true
					},
					{
						text: '加工人员',
						value: 'username',
						filterable: true
					},
					{
						text: '总件数',
						value: 'totalcount',
						filterable: true
					},
					{
						text: '完成件数',
						value: 'completecount',
						filterable: true
					},

					{
						text: '检验日期',
						value: 'checktime',
						filterable: true
					},
					{
						text: '是否异常',
						value: 'checkresult',
						filterable: true
					},
					{
						text: '检验结果描述',
						value: 'description',
						filterable: true
					},
					{
						text: '改进方法',
						value: 'improvedmethod',
						filterable: true
					}
				],
				childrenItems: [],
				processDataList: [],
				processOptions: { //页数
					page: 1,
					//每页行数
					itemsPerPage: 10
				},
				processLoading: true,
				processTotalCount: 0,
				vuetifyDefaultPage: {
					'items-per-page-text': '每页个数',
					'items-per-page-options': [10, 20, 50, 100]
					// 'items-per-page-all-text': '100'
				},

			}
		},
		created() {

		},
		watch: {
			processOptions: {
				handler() {
					this.processQueryLoad()
				},
				deep: true
			},

		},

		methods: {
			selectChildrenEvent(item){
				this.userCommentModel.loadSelectUserItemsUrl = `PDM/PDMPurchaseNeed/GetUserInfoToSelect?bpsnperson=true`
				console.log(item)
			},
			openProcessCheckDialog() {
				this.processCheckDialog = true
				this.loadChildrenList()
			},
			async loadChildrenList() {
				var response = await this.$httpRequest({
					url: `MES/MESQaProcessCheck/LoadInpruductionChildrenList`,
					method: 'get',
				})

				if (response.status == 1) {
					this.childrenItems = response.data
				}
			},
			SetUndefinedNull(obj) {

			},
			async processQueryLoad() {
				this.processLoading = true
				var response = await this.$httpRequest({
					url: `MES/MESQaProcessCheck/LoadPage?checkResult=${this.processQuery.checkResult}&equipmentName=${this.processQuery.equipmentName}&projectCode=${this.processQuery.projectCode}&projectName=${this.processQuery.projectName}&childrenCode=${this.processQuery.childrenCode}&pageNumber=${this.processOptions.page}&pageSize=${this.processOptions.itemsPerPage}`,
					method: 'get',
				})
				if (response.status == 1) {
					this.processDataList = response.data.result
					this.processTotalCount = response.data.pagination.totalRecords
					this.processLoading = false
				} else {
					this.$message.error(response.info)
				}
			},
			refreshprocessQueryLoad() {
				this.processQuery = {}
				this.processQueryLoad()
			},
			async processSubmit() {
				var response = await this.$httpRequest({
					url: `MES/MESQaProcessCheck/Add`,
					method: 'post',
					data: this.processModel
				})

				if (response.status == 1) {
					this.$message.success(response.info)
					this.processCheckDialog = false
					this.refreshprocessQueryLoad()
				} else {
					this.$message.error(response.info)
				}
			},
			cannel() {
				this.processCheckDialog = false
				this.processModel = {
					'equipmentName': '',
					'projectCode': '',
					'projectName': '',
					'childrenCode': '',
					'checkResult': null
				}
			},
			setUserCallBack(user) {
				this.processModel.usercode = user.value
				this.processModel.username = user.realname

			},
		},
	}
</script>

<style>
</style>
